-
Notifications
You must be signed in to change notification settings - Fork 20.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests/fuzzers/bn256: add PairingCheck fuzzer #27252
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO let's keep it in one method, the inputs are the same (and probably the interesting paths/inputs too), so splitting it doesn't make much sense to me
tests/fuzzers/bn256/bn256_fuzz.go
Outdated
// gnark uses a different pairing algorithm than google & cloudflare, so the results might not match up | ||
// which is not a problem because of the bilinearity of the pairing. | ||
|
||
return 1 | ||
} | ||
|
||
func FuzzPairingCheck(data []byte) int { | ||
input := bytes.NewReader(data) | ||
pc, pg, ps := getG1Points(input) | ||
if pc == nil { | ||
return 0 | ||
} | ||
tc, tg, ts := getG2Points(input) | ||
if tc == nil { | ||
return 0 | ||
} | ||
|
||
// Pair the two points and ensure they result in the same output | ||
clOK := cloudflare.PairingCheck([]*cloudflare.G1{pc}, []*cloudflare.G2{tc}) | ||
gOK := google.PairingCheck([]*google.G1{pg}, []*google.G2{tg}) | ||
if clOK != gOK { | ||
panic("pairing check mismatch: cloudflare/google") | ||
} | ||
|
||
cOK, err := bn254.PairingCheck([]bn254.G1Affine{*ps}, []bn254.G2Affine{*ts}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// gnark uses a different pairing algorithm than google & cloudflare, so the results might not match up | |
// which is not a problem because of the bilinearity of the pairing. | |
return 1 | |
} | |
func FuzzPairingCheck(data []byte) int { | |
input := bytes.NewReader(data) | |
pc, pg, ps := getG1Points(input) | |
if pc == nil { | |
return 0 | |
} | |
tc, tg, ts := getG2Points(input) | |
if tc == nil { | |
return 0 | |
} | |
// Pair the two points and ensure they result in the same output | |
clOK := cloudflare.PairingCheck([]*cloudflare.G1{pc}, []*cloudflare.G2{tc}) | |
gOK := google.PairingCheck([]*google.G1{pg}, []*google.G2{tg}) | |
if clOK != gOK { | |
panic("pairing check mismatch: cloudflare/google") | |
} | |
cOK, err := bn254.PairingCheck([]bn254.G1Affine{*ps}, []bn254.G2Affine{*ts}) | |
// gnark uses a different pairing algorithm than google & cloudflare, so the results might not match up | |
// which is not a problem because of the bilinearity of the pairing. | |
// Pair the two points and ensure they result in the same output | |
clOK := cloudflare.PairingCheck([]*cloudflare.G1{pc}, []*cloudflare.G2{tc}) | |
gOK := google.PairingCheck([]*google.G1{pg}, []*google.G2{tg}) | |
if clOK != gOK { | |
panic("pairing check mismatch: cloudflare/google") | |
} | |
cOK, err := bn254.PairingCheck([]bn254.G1Affine{*ps}, []bn254.G2Affine{*ts}) |
tests/fuzzers/bn256/bn256_fuzz.go
Outdated
@@ -141,11 +141,11 @@ func FuzzMul(data []byte) int { | |||
|
|||
func FuzzPair(data []byte) int { | |||
input := bytes.NewReader(data) | |||
pc, pg, ps := getG1Points(input) | |||
pc, pg, _ := getG1Points(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pc, pg, _ := getG1Points(input) | |
pc, pg, ps := getG1Points(input) |
tests/fuzzers/bn256/bn256_fuzz.go
Outdated
if pc == nil { | ||
return 0 | ||
} | ||
tc, tg, ts := getG2Points(input) | ||
tc, tg, _ := getG2Points(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tc, tg, _ := getG2Points(input) | |
tc, tg, ts := getG2Points(input) |
oss-fuzz.sh
Outdated
@@ -93,6 +93,7 @@ compile_fuzzer tests/fuzzers/bitutil Fuzz fuzzBitutilCompress | |||
compile_fuzzer tests/fuzzers/bn256 FuzzAdd fuzzBn256Add | |||
compile_fuzzer tests/fuzzers/bn256 FuzzMul fuzzBn256Mul | |||
compile_fuzzer tests/fuzzers/bn256 FuzzPair fuzzBn256Pair | |||
compile_fuzzer tests/fuzzers/bn256 FuzzPairingCheck fuzzBn256PairingCheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compile_fuzzer tests/fuzzers/bn256 FuzzPairingCheck fuzzBn256PairingCheck |
0a02166
to
6e77459
Compare
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
This reverts commit 625cbea.
This reverts commit 625cbea.
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
This PR removes Gnark from the Pair fuzzer. Because gnark uses a different pairing algorithm, it might produce a different result than the other implementations. However this is not an issue, since the bilinearity of a pairing means both results are correct.
In order to preserve some fuzzing of the gnark pairing, I added a fuzzer that fuzzes the pairingCheck function, which does a pairing and verifies that the result is not equal to one. This is the function we use in ethereum, the pairing algorithm is not under consensus, only the pairing check algorithm.